var http = require('http');
fs = require('fs');
function download(intentPath,imageFileName){
// 对intentpath重新封装
  let path = new String(intentPath);
  path = 'http'+path.substring(path.indexOf(':'));
//path为网络图片地址
  http.get(path,function(req,res){  
  var imgData = '';
  req.setEncoding('binary');
  req.on('data',function(chunk){
    imgData += chunk
  })
  req.on('end',function(){
    //path为本地路径
    fs.writeFile(imageFileName+'.jpg',imgData,'binary',function(err){  
      if(err){console.log('保存出错！')}else{
        console.log('保存成功!')
      }
    })
  })
})
}
download('https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF','peopel');